package com.stylefeng.guns.modular.pay.validator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.baidu.unbiz.fluentvalidator.Validator;
import com.baidu.unbiz.fluentvalidator.ValidatorContext;
import com.baidu.unbiz.fluentvalidator.ValidatorHandler;
import com.stylefeng.guns.modular.pay.model.MchRouter;
import com.stylefeng.guns.modular.pay.service.IMchRouterService;

/**
 * 请求参数验签
 * 
 * @author DevinYang
 * @date 2018年5月29日
 *
 */
@Component
public class MchRouterValidator extends ValidatorHandler<String> implements Validator<String> {
	private final static Logger log = LoggerFactory.getLogger(MchRouterValidator.class);
	@Autowired
	private IMchRouterService mchRouterService;

	
	@Override
	public boolean validate(ValidatorContext context,String param) {
		MchRouter router = mchRouterService.findByPayChannelCode(param);
		if(router==null){
			log.info("支付路由尚未配置或渠道已关闭");
			context.addErrorMsg(String.format("支付路由尚未配置或渠道已关闭"));
			return false;
		}
	   return true;
	}

}
